using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using ExtendedMvc.Elements;

namespace ExtendedMvc {
	public static class HtmlBasicExtensions {

		public static Literal Literal<T>(this ModelViewHtmlHelper<T> html, string text, string id = null) where T : class {
			return new Literal(text, id);
		}

		public static Literal Literal<T>(this ModelViewHtmlHelper<T> html, Expression<Func<T, object>> expression, string id = null) where T : class {
			return new Literal(expression.GetValueFrom(html.ViewDataContainer.Model).ToString(), id);
		}

		public static Button Button<T>(this ModelViewHtmlHelper<T> html, string caption, string id = null) where T : class {
			return new Button(caption, id);
		}

		public static Image Image<T>(this ModelViewHtmlHelper<T> html, string source, string id = null) where T : class {
			source = UrlHelper.GenerateContentUrl(source, html.ViewContext.HttpContext);
			return new Image(source, id);
		}

		public static Image Image<T>(this ModelViewHtmlHelper<T> html, Expression<Func<T, object>> expression, string id = null) where T : class {
			var source = UrlHelper.GenerateContentUrl(expression.GetValueFrom(html.ViewDataContainer.Model).ToString(), html.ViewContext.HttpContext);
			return new Image(source, id);
		}
	}
}
